//
//  HNSH_ShopNetServer.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/25.
//

#import "HNSH_ShopNetServer.h"
#import "HNSH_NetConst.h"

@implementation HNSH_ShopNetServer


//商城首页
+ (NSURLSessionTask *)requestGoodsHomeDataSuccess:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Goods_Home_Data params:@{} from:NO success:success failure:failure];
}


//商城首页
+ (NSURLSessionTask *)requestGoodsHomeDataJXZQSuccess:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Goods_Home_Data_JXZQ params:@{} from:NO success:success failure:failure];
}


// 首页弹窗
+ (NSURLSessionTask *)requestHomeMessageAlertSuccess:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Home_Message_Alert params:@{} from:NO success:success failure:failure];
}


//商城首页推荐商品
+ (NSURLSessionTask *)requestGoodsHomeRecommendWithPage_num:(NSInteger)page_num success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary * params =  @{
                               @"page_size":@"10",
                               @"page_num":@(page_num)};
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Home_Recommend params:params from:NO success:success failure:failure];
}


// 商品列表
+ (NSURLSessionTask *)requestGoodsListWithShop_id:(NSString *)shop_id
                                         mcate_id:(NSString *)mcate_id
                                         scate_id:(NSString *)scate_id
                                          keyword:(NSString *)keyword
                                        sort_type:(NSString *)sort_type
                                        sort_rule:(NSString *)sort_rule
                                             type:(NSString *)type
                                         page_num:(NSInteger)page_num
                                          success:(ST_DataRequestSuccess)success
                                          Failure:(ST_RequestFailure)failure {
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:0];
    if ([shop_id isNotBlank]) {//商家编号
        [dict setObject:shop_id forKey:@"shop_id"];
    }
    if ([mcate_id isNotBlank]) {//一级分类编号
        [dict setObject:mcate_id forKey:@"mcate_id"];
    }
    if ([scate_id isNotBlank]) {//二级分类编号
        [dict setObject:scate_id forKey:@"scate_id"];
    }
    if ([keyword isNotBlank]) {//搜索关键词
        [dict setObject:keyword forKey:@"keyword"];
    }
    if ([sort_type isNotBlank]) {//排序类型 1:综合 2:销量 3:最新 4:价格
        [dict setObject:sort_type forKey:@"sort_type"];
    }
    if ([sort_rule isNotBlank]) {//排序规则 0:降序 1:升序
        [dict setObject:sort_rule forKey:@"sort_rule"];
    }
    if ([type isNotBlank]) {//type = 2 秒杀
        [dict setObject:type forKey:@"type"];
    }
    [dict setObject:@(page_num) forKey:@"page_num"];
    [dict setObject:@"10" forKey:@"page_size"];
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_List params:dict from:NO success:success failure:failure];
}


//商品详情
+ (NSURLSessionTask *)requestGoodsDetailWithGoodsId:(NSString *)goodsId success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Detail,goodsId];
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:urlString params:@{} from:NO success:success failure:failure];
}


//商品规格
+ (NSURLSessionTask *)requestGoodsSpecWithGoodsId:(NSString *)goodsId success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Spec,goodsId];
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:urlString params:@{} from:NO success:success failure:failure];
}


//商品订单确认【确认下单页面】
+ (NSURLSessionTask *)requestGoodsOrderConfirmWithGoodsId:(NSString *)goodsId
                                                  spec_id:(NSString *)spec_id
                                                 quantity:(NSInteger)quantity
                                                from_cart:(NSInteger)from_cart
                                               address_id:(NSString *)address_id
                                                  success:(ST_DataRequestSuccess)success
                                                  Failure:(ST_RequestFailure)failure {
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setValue:@(from_cart) forKey:@"from_cart"];
    if ([goodsId isNotBlank]) {
        [params setValue:goodsId forKey:@"goods_id"];
    }
    if ([spec_id isNotBlank]) {
        [params setValue:spec_id forKey:@"spec_id"];
    }
    if (quantity > 0) {
        [params setValue:@(quantity) forKey:@"quantity"];
    }
    if ([address_id isNotBlank]) {
        [params setValue:address_id forKey:@"address_id"];
    }
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Order_Confirm params:params from:NO success:success failure:failure];
}


//订单创建
+ (NSURLSessionTask *)requestGoodsOrderSubmitWithGoodsId:(NSString *)goodsId
                                                 spec_id:(NSString *)spec_id
                                                quantity:(NSInteger)quantity
                                               from_cart:(NSInteger)from_cart
                                              address_id:(NSString *)address_id
                                               user_note:(NSArray *)user_note
                                                 success:(ST_DataRequestSuccess)success
                                                 Failure:(ST_RequestFailure)failure {
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
    [params setValue:@(from_cart) forKey:@"from_cart"];
    if ([goodsId isNotBlank]) {
        [params setValue:goodsId forKey:@"goods_id"];
    }
    if ([spec_id isNotBlank]) {
        [params setValue:spec_id forKey:@"spec_id"];
    }
    if (quantity > 0) {
        [params setValue:@(quantity) forKey:@"quantity"];
    }
    if ([address_id isNotBlank]) {
        [params setValue:address_id forKey:@"address_id"];
    }
    if (user_note.count > 0) {
        [params setValue:user_note forKey:@"notes"];
    }
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Order_Submit params:params from:NO success:success failure:failure];
}



//订单付款【绿色种子】
+ (NSURLSessionTask *)requestGoodsOrderPaymentWithOrderId:(NSString *)orderId pay_password:(NSString *)pay_password success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary * params = @{@"order_id":orderId,@"pay_password":pay_password};
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Order_Payment params:params from:NO success:success failure:failure];
}



//创建支付订单
+ (NSURLSessionTask *)requestGoodsRechargeCreateWithPrice:(NSString *)price
                                              business_id:(NSString *)business_id
                                            business_type:(NSString *)business_type
                                               channel_id:(NSString *)channel_id
                                             product_code:(NSString *)product_code
                                                  success:(ST_DataRequestSuccess)success
                                                  Failure:(ST_RequestFailure)failure {
    NSDictionary * params = @{@"price":price,@"business_id":business_id,@"business_type":business_type,@"channel_id":channel_id};
    NSMutableDictionary *mutDict = [NSMutableDictionary dictionaryWithDictionary:params];
    if ([channel_id isEqualToString:@"SIFANG_PAY"]) {
        [mutDict setValue:k_url_head forKey:@"return_url"];
    }
    if ([channel_id isEqualToString:@"SANDPAY"]) {
        [mutDict setValue:[ST_UserManager shareInstance].user.uid forKey:@"return_url"];
    }
    if ([product_code isNotBlank]) {
        [mutDict setValue:product_code forKey:@"product_code"];
    }
    
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Recharge_Create params:mutDict from:NO success:success failure:failure];
}



#pragma mark 地址
//收货地址【列表】
+ (NSURLSessionTask *)requestUserAddressListSuccess:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_User_Address_List params:@{} from:NO success:success failure:failure];
}


//收货地址【删除】
+ (NSURLSessionTask *)requestUserAddressDeleteWithAddressId:(NSString *)addressId success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_User_Address_Delete,addressId];
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:urlString params:@{} from:NO success:success failure:failure];
}


//收货地址【新增】
+ (NSURLSessionTask *)requestUserAddressCreateWithParams:(NSDictionary *)params success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_User_Address_Create params:params from:NO success:success failure:failure];
}


//收货地址【编辑】
+ (NSURLSessionTask *)requestUserAddressUpdateWithParams:(NSDictionary *)params success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_User_Address_Update params:params from:NO success:success failure:failure];
}


//地区接口
+ (NSURLSessionTask *)requestRegionListWithParams:(NSDictionary *)params success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Region_List params:params from:YES success:success failure:failure];
}

#pragma mark 购物车
//购物车【信息】
+ (NSURLSessionTask *)requestGoodsCartListSuccess:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Goods_Cart_List params:@{} from:NO success:success failure:failure];
}


//购物车【添加】
+ (NSURLSessionTask *)requestGoodsCartAddWithSpec_id:(NSString *)spec_id quantity:(NSString *)quantity success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary * params = @{@"spec_id":spec_id,
                              @"quantity":quantity};
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Cart_Add params:params from:NO success:success failure:failure];
}


//购物车【更新】
+ (NSURLSessionTask *)requestGoodsCartUpdateWithParams:(NSDictionary *)params success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Cart_Update params:params from:NO success:success failure:failure];
}


//购物车【删除】
+ (NSURLSessionTask *)requestGoodsCartDeleteWithCartIds:(NSArray *)cart_ids success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary *params = @{@"cart_ids":cart_ids};
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Cart_Delete params:params from:NO success:success failure:failure];
}



#pragma mark 订单
//订单列表 
+ (NSURLSessionTask *)requestGoodsOrderListWithStatus:(NSString *)status page_num:(NSInteger)page_num success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary * params =  @{@"status":status,
                               @"page_size":@"10",
                               @"page_num":@(page_num)};
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Goods_Order_List params:params from:YES success:success failure:failure];
}


//订单删除(交易关闭)
+ (NSURLSessionTask *)requestGoodsOrderRemoveWithOrderId:(NSString *)orderId  success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Order_Remove,orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:urlString params:@{} from:NO success:success failure:failure];
}


//订单取消(临时订单/未支付)
+ (NSURLSessionTask *)requestGoodsOrderCancelWithOrderId:(NSString *)orderId  success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Order_Cancel,orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:urlString params:@{} from:NO success:success failure:failure];
}


//确认收货 
+ (NSURLSessionTask *)requestGoodsOrderCompleteWithOrderId:(NSString *)orderId  success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Order_Complete,orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:urlString params:@{} from:NO success:success failure:failure];
}


//订单付款收银台信息
+ (NSURLSessionTask *)requestGoodsOrderPaymentInfoWithOrderId:(NSString *)orderId  success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Order_Payment_Info,orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:urlString params:@{} from:NO success:success failure:failure];
}


//订单详情
+ (NSURLSessionTask *)requestGoodsOrderDetailWithOrderId:(NSString *)orderId  success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Order_Detail,orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:urlString params:@{} from:NO success:success failure:failure];
}


//物流
+ (NSURLSessionTask *)requestGoodsOrderShippingWithOrderId:(NSString *)orderId code:(NSString *)code  success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@?id=%@&code=%@",URL_Goods_Shipping,orderId,code];
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:urlString params:@{} from:NO success:success failure:failure];
}

//售后类型 
+ (NSURLSessionTask *)requestGoodsOrderAfterSalesTypeWithOrderId:(NSString *)orderId success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Order_After_Sales_Type,orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:urlString params:@{} from:NO success:success failure:failure];
}

//售后申请 
+ (NSURLSessionTask *)requestGoodsOrderAfterSalesApplyWithParams:(NSDictionary *)params success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Order_After_Sales_Apply params:params from:NO success:success failure:failure];
}


//售后详情
+ (NSURLSessionTask *)requestGoodsOrderAfterSalesInfoWithOrderId:(NSString *)orderId  success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString *urlString = [NSString stringWithFormat:@"%@/%@",URL_Goods_Order_After_Sales_Info,orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:urlString params:@{} from:NO success:success failure:failure];
}


//售后列表
+ (NSURLSessionTask *)requestGoodsOrderAfterSalesListWithPageNum:(NSInteger)pageNum success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary * params = @{@"page_size":@"10", @"page_num":[NSString stringWithFormat:@"%ld", pageNum]};
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Goods_Order_After_Sales_List params:params from:YES success:success failure:failure];
}


//售后删除 
+ (NSURLSessionTask *)requestGoodsOrderAfterSalesDeleteWithOrderId:(NSString *)orderId success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString * url = [NSString stringWithFormat:@"%@/%@", URL_Goods_Order_After_Sales_Delete, orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:url params:@{} from:NO success:success failure:failure];
}


#pragma mark 收藏
//商品收藏列表
+ (NSURLSessionTask *)requestGoodsFavoriteListSuccess:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Goods_Favorite_List params:@{} from:NO success:success failure:failure];
}

//商品收藏操作
+ (NSURLSessionTask *)requestGoodsFavoriteOperateWithGoodsId:(NSString *)goodsId operateType:(NSString *)operateType success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary * params = @{@"goods_id":goodsId,@"operate_type":operateType};
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Goods_Favorite_Operate params:params from:NO success:success failure:failure];
}


#pragma mark 商圈
//商圈导航栏
+ (NSURLSessionTask *)requestBusinessCircleNavTitleSuccess:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Business_Circle_Nav_Title params:@{} from:NO success:success failure:failure];
}

// 商圈店铺列表
+ (NSURLSessionTask *)requestBusinessCircleShopListWithCategory_id:(NSString *)category_id
                                                           keyword:(NSString *)keyword
                                                              type:(NSInteger)type
                                                       region_code:(NSString *)region_code
                                                          latitude:(NSString *)latitude
                                                         longitude:(NSString *)longitude
                                                          page_num:(NSInteger)page_num
                                                           success:(ST_DataRequestSuccess)success
                                                           Failure:(ST_RequestFailure)failure {
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:0];
    if ([category_id isNotBlank]) {//分类编号
        [dict setObject:category_id forKey:@"category_id"];
    }
    if ([keyword isNotBlank]) {//查询关键词
        [dict setObject:keyword forKey:@"keyword"];
    }
    if ([region_code isNotBlank] && type == 1) {//区域编码   type==0 不传地区编码
        [dict setObject:region_code forKey:@"region_code"];
    }
    if ([latitude isNotBlank]) {//纬度
        [dict setObject:latitude forKey:@"latitude"];
    }
    if ([longitude isNotBlank]) {//经度
        [dict setObject:longitude forKey:@"longitude"];
    }
    if ([keyword isNotBlank]) {//查询关键词
        [dict setObject:keyword forKey:@"keyword"];
    }
    [dict setObject:@(type) forKey:@"type"];
    [dict setObject:@(page_num) forKey:@"page_num"];
    [dict setObject:@"10" forKey:@"page_size"];
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Business_Circle_Shop_List params:dict from:NO success:success failure:failure];
}

+ (NSURLSessionTask *)requestBusinessCircleUploadVoucherWithShopId:(NSString *)shop_id amount:(NSString *)amount image_url:(NSString *)image_url success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary * params =  @{@"shop_id":shop_id,
                               @"amount":amount,
                               @"image_url":image_url
    };
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:URL_Business_Circle_Upload_Voucher params:params from:NO success:success failure:failure];
}

//消费凭证记录
+ (NSURLSessionTask *)requestBusinessCircleVoucherListWithPageNum:(NSInteger)pageNum type:(NSInteger)type success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSDictionary * params = @{@"page_size":@"10", @"page_num":[NSString stringWithFormat:@"%ld", pageNum],@"type":[NSString stringWithFormat:@"%ld", type]};
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_Business_Circle_Voucher_List params:params from:YES success:success failure:failure];
}

//订单状态
+ (NSURLSessionTask *)requestGoodsRechargeVerifyWithOrderId:(NSString *)orderId success:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    NSString * url = [NSString stringWithFormat:@"%@%@", URL_Goods_Recharge_Verify, orderId];
    return [ST_BaseNetManager requestMethod:HttpMethodPost urlString:url params:@{} from:NO success:success failure:failure];
}

//消费额度信息
+ (NSURLSessionTask *)requestUserConsumeQuotaSuccess:(ST_DataRequestSuccess)success Failure:(ST_RequestFailure)failure {
    return [ST_BaseNetManager requestMethod:HttpMethodGet urlString:URL_User_Consume_Quota params:@{} from:NO success:success failure:failure];
}


@end
